//
//  ViewController.m
//  06-NavigationController
//
//  Created by 王道林 on 16/7/21.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "ViewController.h"
#import "PushViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    // 设置navigationBar的属性
    
    // 1. title  标题
    self.title = @"我是标题";
    self.navigationItem.title = @"xxx,呵呵";
    
    // 2. titleView  标题视图
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"wanghuang", @"hanxu"]];
    segment.frame = CGRectMake(0, 0, 150, 44);
    self.navigationItem.titleView = segment;
    
    // 3.
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(comeBack:)];
    // 4.rightBarButtonItem
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
    
    // 5
    //  数组中放UIBarButtonItem
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(comeBack:)];
    
     UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(comeBack:)];
    
     self.navigationItem.leftBarButtonItems = @[item1, item2];
    
    
    // 7 . 隐藏navigationBar  YES隐藏,  默认NO
    // iOS7 以后默认为 YES
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.hidden = NO;
    
    // 8. style  枚举
    
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    // 9.navigationBar 的背景颜色
    self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
    
    // 10  barTintColor  Bar 的颜色
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    
    
    // 11 .
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    //  12translucent 管理半透明效果, YES为开启, NO为关闭
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor blueColor];
    button.frame = CGRectMake(0, 0, 200, 200)
    ;
    [self.view addSubview:button];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    // 设置为YES时. self.view坐标系从零点开始
    // 设置为NO时, self.view坐标系从navigationBar下开始
    self.navigationController.navigationBar.translucent = NO;
    
    // 13 . 改变坐标效果, 与透明度为NO效果一样
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    NSLog(@"%@", NSStringFromCGRect(self.view.frame));
    
    
    //页面跳转
    // 1. push   入栈
    // 2. pull   出栈
    // 3. viewControllers  存放navigationController里所有的控制器
 //   self.navigationController.viewControllers
    // 4. topViewController  栈顶视图控制器
    // 5. visibleViewController 可见视图控制器
    
    
    
}
- (void)buttonAction:(UIButton *)button
{
    // 将视图控制器入栈
    [self.navigationController pushViewController:[[PushViewController alloc] init] animated:YES];
    
    
    
    
}


- (void)add:(UIBarButtonItem *)bar
{
    NSLog(@"加");
}


- (void)comeBack:(UIBarButtonItem *)barButtonItem
{
    NSLog(@"返回");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
